package com.smart.modules.genealogy.controller;


import com.smart.modules.genealogy.dto.GenealogyPersonDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.modules.genealogy.domain.GenealogyPerson;
import com.smart.modules.genealogy.service.IGenealogyPersonService;
import com.smart.system.common.result.Result;
import com.smart.system.common.result.PageResult;


/**
 * 家谱人员Controller
 */
@RestController
@RequestMapping("/genealogy/person")
public class GenealogyPersonController
{
    @Autowired
    private IGenealogyPersonService genealogyPersonService;

    /**
     * 构建族谱树
     * @return
     */
    @GetMapping("/buildTreeList")
    public Result buildGenealogyByGenealogyId(@RequestParam Long genealogyId){
        return genealogyPersonService.buildGenealogyByGenealogyId(genealogyId);
    }


    /**
     * 查询家谱人员列表
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:person:list')")
    @GetMapping("/list")
    public PageResult list(GenealogyPerson genealogyPerson)
    {

        IPage<GenealogyPerson> pageModel = new Page<GenealogyPerson>(genealogyPerson.getPageNum(),genealogyPerson.getPageSize());
        IPage<GenealogyPerson> page = genealogyPersonService.selectGenealogyPersonList(pageModel,genealogyPerson);
        return PageResult.success(page);
    }


    /**
     * 获取家谱人员详细信息
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:person:query')")
    @GetMapping(value = "/{genealogyPersonId}")
    public Result getInfo(@PathVariable("genealogyPersonId") Long genealogyPersonId)
    {
        return Result.success(genealogyPersonService.selectGenealogyPersonByGenealogyPersonId(genealogyPersonId));
    }

    /**
     * 新增家谱人员
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:person:add')")
    @PostMapping
    public Result add(@RequestBody GenealogyPersonDto genealogyPerson)
    {
        return Result.success(genealogyPersonService.insertGenealogyPerson(genealogyPerson));
    }

    ///**
    // * 新增家谱人员
    // */
    ////@PreAuthorize("@ss.hasPermi('genealogy:person:add')")
    //@PostMapping
    //public Result add(@RequestBody GenealogyPerson genealogyPerson)
    //{
    //    return Result.success(genealogyPersonService.insertGenealogyPerson(genealogyPerson));
    //}


    /**
     * 修改家谱人员
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:person:edit')")
    @PutMapping
    public Result edit(@RequestBody GenealogyPerson genealogyPerson)
    {
        return Result.success(genealogyPersonService.updateGenealogyPerson(genealogyPerson));
    }

    /**
     * 删除家谱人员
     */
    //@PreAuthorize("@ss.hasPermi('genealogy:person:remove')")
    @DeleteMapping("/{genealogyPersonIds}")
    public Result remove(@PathVariable Long[] genealogyPersonIds)
    {
        return Result.success(genealogyPersonService.deleteGenealogyPersonByGenealogyPersonIds(genealogyPersonIds));
    }
}
